<template>
    <div class="jobcommon body jinli">
        <!-- 头部 end-->
        <div class="show_title font15">
            <div class="t_bar"></div>
            基本资料 <span class="red_txt">*</span>
        </div>
        <div class="show_1" v-if="JSON.stringify(resume_info) != '{}'">
            <div class="s1_ava">
                <img :src="resume_info.photo_img" alt="" />
                <div class="ava_edit font12">编辑</div>
            </div>
            <div class="s1_tx1 font15">{{ resume_info.fullname }}</div>
            <div class="s1_tx2 font13">
                {{ resume_info.sex_cn }} |
                {{ new Date().getFullYear() - resume_info.birthdate }}岁 |
                {{ resume_info.experience_cn }} | {{ resume_info.education_cn }}
            </div>
            <div class="s1_tx3 substring font13">
                {{ resume_info.residence ? resume_info.residence : '未填写' }}
            </div>
            <a @click="openProps(0)" class="it_edit font12">修改</a>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            求职意向 <span class="red_txt">*</span>
        </div>
        <div class="show_2 font13" v-if="JSON.stringify(resume_info) != '{}'">
            <div class="s2_line">
                <div class="s2l">求职状态：</div>
                <div class="s2r">{{ resume_info.current_cn }}</div>
                <div class="clear"></div>
            </div>
            <div class="s2_line">
                <div class="s2l">工作性质：</div>
                <div class="s2r">{{ resume_info.nature_cn }}</div>
                <div class="clear"></div>
            </div>
            <div class="s2_line">
                <div class="s2l">期望行业：</div>
                <div class="s2r">{{ resume_info.trade_cn }}</div>
                <div class="clear"></div>
            </div>
            <div class="s2_line">
                <div class="s2l">期望职位：</div>
                <div class="s2r">{{ resume_info.intention_jobs }}</div>
                <div class="clear"></div>
            </div>
            <div class="s2_line">
                <div class="s2l">工作地区：</div>
                <div class="s2r">{{ resume_info.district_cn }}</div>
                <div class="clear"></div>
            </div>
            <div class="s2_line">
                <div class="s2l">期望薪资：</div>
                <div class="s2r">{{ resume_info.wage_cn }}</div>
                <div class="clear"></div>
            </div>
            <a @click="openProps(1)" class="it_edit font12">修改</a>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            自我介绍
        </div>
        <div class="show_3 font12" v-if="JSON.stringify(resume_info) != '{}'">
            {{ resume_info.specialty }}
            <a @click="openProps(2)" class="it_edit font12">修改</a>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            教育经历
        </div>

        <div class="show_5">
            <a @click="(dataProps = {}), openProps(3)" class="it_add font12"
                >添加</a
            >
            <div id="J_education" v-if="JSON.stringify(education_list) != '{}'">
                <div
                    class="s_item last"
                    v-for="(item, index) in education_list.list"
                    :key="index"
                >
                    <div
                        class="sit_edit"
                        @click="(dataProps = item), openProps(3)"
                    ></div>
                    <div
                        class="J_delete sit_del"
                        @click="deleList(item.pid, item.id, 'ResumeEducation')"
                    ></div>
                    <div class="si_t1 substring font13">{{ item.school }}</div>
                    <div class="si_t2 font12">
                        {{ item.education_cn }}
                    </div>
                    <div class="si_t3 font12">
                        {{ item.startyear }}年-{{ item.startmonth }}月 至
                        {{ item.endyear }}年-{{ item.endmonth }}月
                    </div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            工作经历
        </div>
        <div class="show_5">
            <a @click="(dataProps = {}), openProps(4)" class="it_add font12"
                >添加</a
            >
            <div id="J_work" v-if="JSON.stringify(work_list) != '{}'">
                <div
                    class="s_item"
                    v-for="(item, index) in work_list.list"
                    :key="index"
                >
                    <div
                        class="sit_edit"
                        @click="(dataProps = item), openProps(4)"
                    ></div>
                    <div
                        class="J_delete sit_del"
                        @click="deleList(item.pid, item.id, 'ResumeWork')"
                    ></div>
                    <div class="si_t1 substring font13">
                        {{ item.companyname }}
                    </div>
                    <div class="si_t2 font12">{{ item.jobs }}</div>
                    <div class="si_t3 font12">
                        {{ item.startyear }}年-{{ item.startmonth }}月 至
                        {{ item.endyear }}年-{{ item.endmonth }}月
                    </div>
                    <div class="si_t4 font12">{{ item.achievements }}</div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            培训经历
        </div>
        <div class="show_5">
            <a @click="(dataProps = {}), openProps(5)" class="it_add font12"
                >添加</a
            >
            <div id="J_training" v-if="JSON.stringify(train_list) != '{}'">
                <div
                    class="s_item"
                    v-for="(item, index) in train_list.list"
                    :key="index"
                >
                    <div
                        class="sit_edit"
                        @click="(dataProps = item), openProps(5)"
                    ></div>
                    <div
                        class="J_delete sit_del"
                        @click="deleList(item.pid, item.id, 'ResumeTraining')"
                    ></div>
                    <div class="si_t1 substring font13">{{ item.agency }}</div>
                    <div class="si_t2 font12">{{ item.course }}</div>
                    <div class="si_t3 font12">
                        {{ item.startyear }}年-{{ item.startmonth }}月 至
                        {{ item.endyear }}年-{{ item.endmonth }}月
                    </div>
                    <div class="si_t4 font12">{{ item.description }}</div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            项目经历
        </div>
        <div class="show_5">
            <a @click="(dataProps = {}), openProps(6)" class="it_add font12"
                >添加</a
            >
            <div id="J_project" v-if="JSON.stringify(project_list) != '{}'">
                <div
                    class="s_item"
                    v-for="(item, index) in project_list.list"
                    :key="index"
                >
                    <div
                        class="sit_edit"
                        @click="(dataProps = item), openProps(6)"
                    ></div>
                    <div
                        class="J_delete sit_del"
                        @click="deleList(item.pid, item.id, 'ResumeProject')"
                    ></div>
                    <div class="si_t1 substring font13">
                        {{ item.projectname }}
                    </div>
                    <div class="si_t2 font12">{{ item.role }}</div>
                    <div class="si_t3 font12">
                        {{ item.startyear }}年-{{ item.startmonth }}月 至
                        {{ item.endyear }}年-{{ item.endmonth }}月
                    </div>
                    <div class="si_t4 font12">{{ item.description }}</div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            获得证书
        </div>
        <div class="show_5">
            <a @click="(dataProps = {}), openProps(7)" class="it_add font12"
                >添加</a
            >
            <div id="J_credent" v-if="JSON.stringify(credent_list) != '{}'">
                <div
                    class="s_item"
                    v-for="(item, index) in credent_list.list"
                    :key="index"
                >
                    <div
                        class="sit_edit"
                        @click="(dataProps = item), openProps(7)"
                    ></div>
                    <div
                        class="J_delete sit_del"
                        @click="deleList(item.pid, item.id, 'ResumeCredent')"
                    ></div>
                    <div class="si_t1 substring font13">{{ item.name }}</div>
                    <div class="si_t2 font12">
                        {{ item.year }}年-{{ item.month }}月
                    </div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            语言能力
        </div>
        <div class="show_6">
            <a @click="(dataProps = {}), openProps(8)" class="it_add font12"
                >添加</a
            >
            <div id="J_language" v-if="JSON.stringify(language_list) != '{}'">
                <div
                    class="s6_line font13"
                    v-for="(item, index) in language_list.list"
                    :key="index"
                >
                    {{ item.language_cn }}·{{ item.level_cn }}
                    <a
                        class="sit_edit"
                        @click="(dataProps = item), openProps(8)"
                    ></a>
                    <div
                        class="sit_del J_delete"
                        @click="deleList(item.pid, item.id, 'ResumeLanguage')"
                    ></div>
                </div>
            </div>
        </div>
        <div class="show_title font15">
            <div class="t_bar"></div>
            特长标签
        </div>

        <div class="show_7" id="J_tags" pid="2">
            <a @click="openProps(9)" class="it_add font12">添加</a>
            <div
                style="overflow: hidden"
                v-if="JSON.stringify(resume_info) != '{}'"
            >
                <div
                    class="J_tagList s7_item font12"
                    tid="166"
                    v-for="(item, index) in resume_info.tag"
                    :key="index"
                >
                    {{ item }}
                    <div class="del" @click="delebiaoqin(index)"></div>
                </div>
            </div>
            <div class="clear"></div>
        </div>

        <!-- 个人信息编辑 -->
        <EditResumeInfo
            v-if="proprKey === 0"
            @closeProps="closeProps"
            :guidance="guidance"
            :resume_info="resume_info"
        />

        <!-- 求职意向 -->
        <QiuzhiYixiang
            v-if="proprKey === 1"
            @closeProps="closeProps"
            :guidance="guidance"
            :resume_info="resume_info"
        />

        <!-- 自我介绍 -->
        <Ziwojieshao
            v-if="proprKey === 2"
            @closeProps="closeProps"
            :resume_info="resume_info"
        />

        <!-- 教育经历 -->
        <Jiaoyujingli
            v-if="proprKey === 3"
            @closeProps="closeProps"
            :education="guidance.education"
            :dataProps="dataProps"
        />

        <!-- 工作经历 -->
        <Gongzuojingli
            v-if="proprKey === 4"
            @closeProps="closeProps"
            :dataProps="dataProps"
        />

        <!-- 培训经历 -->
        <Peixunjingli
            v-if="proprKey === 5"
            @closeProps="closeProps"
            :dataProps="dataProps"
        />

        <!-- 项目经历 -->
        <Xiangmujingli
            v-if="proprKey === 6"
            @closeProps="closeProps"
            :dataProps="dataProps"
        />

        <!-- 获得证书 -->
        <Huodezhengshu
            v-if="proprKey === 7"
            @closeProps="closeProps"
            :dataProps="dataProps"
        />

        <!-- 语言能力 -->
        <Yuyannengli
            v-if="proprKey === 8"
            @closeProps="closeProps"
            :dataProps="dataProps"
            :language="guidance.language"
            :language_level="guidance.language_level"
        />

        <!-- 特长标签 -->
        <Techangbiaoqian
            v-if="proprKey === 9"
            @closeProps="closeProps"
            :checktag="resume_info.tag"
            :tags="guidance.tags"
            :pid="resume_info.pid"
        />

        <div class="zhanwei"></div>
    </div>
</template>

<script>
import EditResumeInfo from '../../components/jobUser/EditResumeInfo';
import QiuzhiYixiang from '../../components/jobUser/QiuzhiYixiang';
import Ziwojieshao from '../../components/jobUser/Ziwojieshao';
import Jiaoyujingli from '../../components/jobUser/Jiaoyujingli';
import Gongzuojingli from '../../components/jobUser/Gongzuojingli';
import Peixunjingli from '../../components/jobUser/Peixunjingli';
import Xiangmujingli from '../../components/jobUser/Xiangmujingli';
import Huodezhengshu from '../../components/jobUser/Huodezhengshu';
import Yuyannengli from '../../components/jobUser/Yuyannengli';
import Techangbiaoqian from '../../components/jobUser/Techangbiaoqian';

import { axiosPost } from '../../axios';
import { Toast, Dialog } from 'vant';
export default {
    name: '',
    components: {
        EditResumeInfo,
        QiuzhiYixiang,
        Ziwojieshao,
        Jiaoyujingli,
        Gongzuojingli,
        Peixunjingli,
        Xiangmujingli,
        Huodezhengshu,
        Yuyannengli,
        Techangbiaoqian,
    },
    data() {
        return {
            // 弹窗开关数据
            proprKey: '',

            // 公共数据
            dataProps: {},

            // 基本资料
            resume_info: {},
            // 教育经历
            education_list: {},

            // 工作经历
            work_list: {},
            // 培训经历
            train_list: {},
            // 项目经历
            project_list: {},
            // 获得证书
            credent_list: {},
            // 语言能力
            language_list: {},
        };
    },
    computed: {},
    mounted() {
        this.getJinanli();
    },
    methods: {
        // 标签删除接口
        delebiaoqin(index) {
            let tags = [];
            for (let i in this.resume_info.tag) {
                if (index != i) {
                    tags.push(i);
                }
            }
            Dialog.confirm({
                title: '',
                message: '您真的要删除吗？',
            })
                .then(() => {
                    axiosPost(
                        '/apis/resume/edit_speciality',
                        {
                            tag: tags.map((option) => option).join(','),
                            pid: this.resume_info.pid,
                        },
                        (res) => {
                            Toast({
                                message: res.msg,
                                duration: 2000,
                            });
                            if (res.status != 1) {
                                return;
                            }
                            this.getJinanli();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },
        // 统一的列表删除接口
        deleList(pid, id, type) {
            Dialog.confirm({
                title: '',
                message: '您真的要删除吗？',
            })
                .then(() => {
                    axiosPost(
                        '/apis/resume/del',
                        {
                            pid: pid,
                            id: id,
                            type: type,
                        },
                        (res) => {
                            Toast({
                                message: res.msg,
                                duration: 2000,
                            });
                            if (res.status != 1) {
                                return;
                            }
                            this.getJinanli();
                        }
                    );
                })
                .catch(() => {
                    // on cancel
                });
        },
        // 打开弹窗
        openProps(data) {
            document.body.style.overflow = 'hidden';
            this.proprKey = data;
        },
        // 关闭弹窗
        closeProps(data) {
            document.body.style.overflow = '';
            if (data.key) {
                this.getJinanli();
            }
            this.proprKey = '';
        },
        // 创建简历
        createJianli() {
            axiosPost(
                '/apis/resume/add_basic',
                {
                    pid: '2',
                },
                (res) => {
                    // console.log(res);
                    if (res.status != 1) {
                        return Toast({
                            message: res.msg,
                            duration: 2000,
                        });
                    }
                }
            );
        },
        // 获取简历信息
        getJinanli() {
            axiosPost(
                '/apis/personal/index',
                {
                    pid: '2',
                },
                (res) => {
                    // console.log(res);
                    if (res.status != 1 && res.status != 0) {
                        return Toast({
                            message: res.msg,
                            duration: 2000,
                        });
                    }
                    this.getJianliYindao(res.data.resume_info.id);
                    // 基本信息
                    this.resume_info = res.data.resume_info
                        ? res.data.resume_info
                        : {};
                    // 教育经历
                    this.education_list = res.data.education_list
                        ? res.data.education_list
                        : {};
                    // 工作经历
                    this.work_list = res.data.work_list
                        ? res.data.work_list
                        : {};
                    // 培训经历
                    this.train_list = res.data.train_list
                        ? res.data.train_list
                        : {};
                    // 项目经历
                    this.project_list = res.data.project_list
                        ? res.data.project_list
                        : {};
                    // 获得证书
                    this.credent_list = res.data.credent_list
                        ? res.data.credent_list
                        : {};
                    // 语言能力
                    this.language_list = res.data.language_list
                        ? res.data.language_list
                        : {};
                }
            );
        },

        // 获取简历引导
        getJianliYindao(id) {
            axiosPost(
                '/apis/resume/guidance',
                {
                    pid: id,
                },
                (res) => {
                    // console.log(res);
                    if (res.status != 1) {
                        return Toast({
                            message: res.msg,
                            duration: 2000,
                        });
                    }
                    this.guidance = res.data;
                    this.proprKey = '';
                }
            );
        },
    },
};
</script>
<style lang="less" src="../../assets/css/jobCommon.less" scope></style>
<style lang="css" src="../../assets/css/person_edit.css" scope></style>
<style lang="less" scope></style>
